package mz.matafe.bolao

/**
 * Match Service.
 *
 * <p>Utility services for Match
 *
 * @since 0.0.1
 * @author <a href="mailto:matafe@gmail.com">Maurício T. Ferraz</a>
 */
class MatchService {

    boolean transactional = true

    boolean isAvailableToBet(Match match){
        if (match.finished)
            return false;
        def now = new Date()
        def oneHrLater = match.matchDate.clone()
        oneHrLater.hours = match.matchDate.hours-1
        log.debug "Match [" + match.matchNumber + "] Date: " + match.matchDate.format('dd/MM/yyyy HH:mm') + " Last Time To Bet:" + oneHrLater.format('dd/MM/yyyy HH:mm')
        boolean isAvailable = !now.after(oneHrLater)
        log.debug isAvailable
        return isAvailable
    }
}
